package com.example.backend.controller;

import com.example.backend.service.ImageUploadService;
import com.example.backend.utils.Response;
import com.example.backend.utils.ResponseStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/images")
public class ImageUploadController {
    @Autowired
    ImageUploadService service;

    @PostMapping
    public Response<Integer> upload(@RequestParam("file")MultipartFile multipartFile) {
        int result = service.save(multipartFile);
        return result != -1 ?
                Response.Ok("image upload success", ResponseStatus.OK.getValue())
                : Response.Error("image upload failed", ResponseStatus.ERROR.getValue());
    }
}
